package com.hx.zhg.constant;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 序列化方式枚举
 */
public enum SerializeTypeEnum {

	JSON((byte)0),
	PROTOBUF((byte)1);

	private static Set<Byte> TYPE_SET = new HashSet<>();

	private static final Map<Byte, SerializeTypeEnum> TYPE_MAP = new HashMap<>();
	static {
		for (SerializeTypeEnum chanelEnum : values()) {
			TYPE_MAP.put(chanelEnum.getSerializeType(), chanelEnum);
		}
		TYPE_SET = TYPE_MAP.keySet();
	}

	public static Set<Byte> getChannelSet() {
		return TYPE_SET;
	}
	/**
	 * 根据channel值获取枚举
	 * @param channel
	 * @return
	 */
	public static SerializeTypeEnum getEnum(Byte channel) {
		return TYPE_MAP.get(channel);
	}

	/**
	 * 判断channel是否有效（是否包含在当前枚举中）
	 * @param channel
	 * @return
	 */
	public static boolean isValid(Byte channel) {
		return TYPE_SET.contains(channel);
	}

	SerializeTypeEnum(Byte serializeType) {
		this.serializeType = serializeType;
	}
	
	private Byte serializeType;

	public Byte getSerializeType() {
		return serializeType;
	}

	public void setSerializeType(Byte serializeType) {
		this.serializeType = serializeType;
	}
}
